package flc.ast.adapter;

import android.view.View;

import androidx.annotation.NonNull;

import com.chad.library.adapter.base.provider.BaseItemProvider;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;

import flc.ast.R;
import flc.ast.bean.MyDebugBean;
import stark.common.basic.adaptermutil.StkProviderMultiAdapter;
import stark.common.basic.adaptermutil.StkSingleSpanProvider;

public class DebugAdapter extends StkProviderMultiAdapter<MyDebugBean> {

    public DebugAdapter() {
        addItemProvider(new StkSingleSpanProvider(30));
        addItemProvider(new DebugProvider());
    }

    private boolean isEdit;

    public boolean isEdit() {
        return isEdit;
    }

    public void setEdit(boolean edit) {
        isEdit = edit;
    }

    private class DebugProvider extends BaseItemProvider<MyDebugBean> {
        @Override
        public int getItemViewType() {
            return StkProviderMultiAdapter.TYPE_VIEW;
        }

        @Override
        public int getLayoutId() {
            return R.layout.item_debug;
        }

        @Override
        public void convert(@NonNull BaseViewHolder baseViewHolder, MyDebugBean bean) {
            baseViewHolder.setText(R.id.tvDebugItemName, bean.getName());
            baseViewHolder.setText(R.id.tvDebugItemType, bean.getType());
            baseViewHolder.setText(R.id.tvDebugItemHost, bean.getHost());
            if (isEdit) {
                baseViewHolder.getView(R.id.ivDebugItemDelete).setVisibility(View.VISIBLE);
            } else {
                baseViewHolder.getView(R.id.ivDebugItemDelete).setVisibility(View.INVISIBLE);
            }
        }
    }
}
